package org.zjx.app.action.route;

import org.zjx.analysis.analyze.game.GameAnalysis;
import org.zjx.app.action.window.ClickSceneAction;
import org.zjx.command.entity.screen.Address;
import org.zjx.window.action.Action;
import org.zjx.window.window.IWindow;

public class SceneTransferAction extends Action {
    private final Address targetAddress;
    private final Address standPosition;
    private final Address clickPosition;

    public SceneTransferAction(IWindow targetWindow, Address targetAddress, Address standPosition, Address clickPosition) {
        super(targetWindow, false);
        this.targetAddress = targetAddress;
        this.standPosition = standPosition;
        this.clickPosition = clickPosition;
    }

    @Override
    protected void doExecute() throws Exception {
        if (getAddressNow().near(targetAddress, 3)) return;
        if (!getAddressNow().near(standPosition, 3)) {
            targetWindow.submitAction(new BaseRouteAction(targetWindow, standPosition));
        }else {
            targetWindow.submitAction(new ClickSceneAction(targetWindow, clickPosition,ClickSceneAction.ClickType.SCENE));
        }
    }

    public Address getAddressNow() {
        GameAnalysis gameAnalysis = new GameAnalysis(targetWindow);
        return gameAnalysis.getAddress();
    }
}
